package com.aptemo.webetek.server.data;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

/**
 * Child of Stake (Bet)
 * 
 * @author
 * 
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class PickSnapshot
{

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key		key;

	private String	sid;

	@Persistent
	@Extension(vendorName = "datanucleus", key = "gae.parent-pk", value = "true")
	private Key		parentKey;
	// @Persistent
	// private Bet bet;

	@Persistent
	private Key		origKey;

	// prepared for bookies
	@Persistent
	private Double	odds	= Double.POSITIVE_INFINITY;

	public PickSnapshot(Pick pick)
	{
		// save reference...
		this.origKey = pick.getId();
		// save odds...
		this.odds = pick.getOdds();
	}

	public Key getOrigKey()
	{
		return origKey;
	}

	public Double getSnapshotOdds()
	{
		return odds;
	}

	public String getSid()
	{
		if (sid == null)
		{
			// auto create WEB SAFE key representation...
			this.sid = KeyFactory.keyToString(key);
		}

		return sid;
	}

}
